/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.crm.dao.CustomerDAO;
/*     */ import com.feeyin.radar.sys.dao.DepartmentDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.model.Department;
/*     */ import com.feeyin.radar.sys.service.DepartmentService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class DepartmentServiceImpl
/*     */   implements DepartmentService
/*     */ {
/*     */   private DepartmentDAO departmentDAO;
/*     */   private UserDAO userDAO;
/*     */   private CustomerDAO customerDAO;
/*     */ 
/*     */   public DepartmentDAO getDepartmentDAO()
/*     */   {
/*  28 */     return this.departmentDAO;
/*     */   }
/*     */ 
/*     */   public void setDepartmentDAO(DepartmentDAO departmentDAO) {
/*  32 */     this.departmentDAO = departmentDAO;
/*     */   }
/*     */ 
/*     */   public List getDepartments() {
/*  36 */     return this.departmentDAO.getDepartments();
/*     */   }
/*     */ 
/*     */   public UserDAO getUserDAO() {
/*  40 */     return this.userDAO;
/*     */   }
/*     */ 
/*     */   public void setUserDAO(UserDAO userDAO) {
/*  44 */     this.userDAO = userDAO;
/*     */   }
/*     */ 
/*     */   public CustomerDAO getCustomerDAO() {
/*  48 */     return this.customerDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerDAO(CustomerDAO customerDAO) {
/*  52 */     this.customerDAO = customerDAO;
/*     */   }
/*     */ 
/*     */   public List getDepartmentsByActivity()
/*     */   {
/*  67 */     return null;
/*     */   }
/*     */ 
/*     */   public List getDepartmentByParentId(Integer parentId) {
/*  71 */     return this.departmentDAO.getDepartmentByParentId(parentId);
/*     */   }
/*     */ 
/*     */   public Department getDepartment(Integer id) {
/*  75 */     return this.departmentDAO.getDepartment(id);
/*     */   }
/*     */ 
/*     */   public String getDepartmentCode() {
/*  79 */     String deptCode = "";
/*  80 */     Integer maxId = this.departmentDAO.getDepartmentMaxId();
/*  81 */     if (maxId != null)
/*  82 */       maxId = Integer.valueOf(maxId.intValue() + 1);
/*     */     else {
/*  84 */       maxId = Integer.valueOf(1);
/*     */     }
/*  86 */     deptCode = maxId.toString();
/*  87 */     return deptCode;
/*     */   }
/*     */ 
/*     */   public Department getDepartmentByDeptName(String deptName) {
/*  91 */     return this.departmentDAO.getDepartmentByDeptName(deptName);
/*     */   }
/*     */ 
/*     */   public boolean isRepeatUpdateDepartment(Department department) {
/*  95 */     if (department == null) return false;
/*     */ 
/*  97 */     Department oldDept = new Department();
/*  98 */     oldDept = this.departmentDAO.getDepartment(department.getId());
/*     */ 
/* 100 */     if (oldDept == null) return false;
/* 101 */     if (!department.getDeptName().equals(oldDept.getDeptName())) {
/* 102 */       Department otherDept = new Department();
/* 103 */       otherDept = this.departmentDAO.getDepartmentByDeptName(department.getDeptName());
/* 104 */       if (otherDept != null) return true;
/*     */     }
/* 106 */     return false;
/*     */   }
/*     */ 
/*     */   public boolean isUseDepartment(Integer deptId) {
/* 110 */     if (deptId == null) return false;
/* 111 */     List users = new ArrayList();
/* 112 */     users = this.userDAO.getUsersByDeptId(deptId);
/* 113 */     if ((users != null) && (users.size() > 0)) return true;
/*     */ 
/* 115 */     List customers = new ArrayList();
/* 116 */     customers = this.customerDAO.getCustomersByDeptId(deptId);
/* 117 */     return (customers != null) && (customers.size() > 0);
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptIdAndSubDeptIdsByDeptId(Integer deptId)
/*     */   {
/* 127 */     return this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByDeptId(deptId);
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptIdAndSubDeptIdsByUserId(Integer userId) {
/* 131 */     return this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByUserId(userId);
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptNameAndSubDeptNamesByUserId(Integer userId) {
/* 135 */     return this.departmentDAO.getCurrentDeptNameAndSubDeptNamesByUserId(userId);
/*     */   }
/*     */ 
/*     */   public List getCurrentDeptAndSubDeptsByUserId(Integer userId) {
/* 139 */     return this.departmentDAO.getCurrentDeptAndSubDeptsByUserId(userId);
/*     */   }
/*     */ 
/*     */   public boolean insertDepartment(Department department) {
/* 143 */     if (department == null) return false;
/* 144 */     boolean result1 = false;
/* 145 */     boolean result2 = false;
/*     */ 
/* 147 */     result1 = this.departmentDAO.insertDepartment(department);
/*     */ 
/* 149 */     Department addedDept = new Department();
/* 150 */     addedDept = this.departmentDAO.getDepartmentByDeptCode(department.getDeptCode());
/* 151 */     if (addedDept == null) return false;
/*     */ 
/* 153 */     if (department.getParentId().intValue() == 0) {
/* 154 */       department.setDeptSeq("0." + addedDept.getId() + ".");
/*     */     }
/*     */     else {
/* 157 */       Department parentDept = new Department();
/* 158 */       parentDept = this.departmentDAO.getDepartment(department.getParentId());
/* 159 */       if (parentDept == null) return false;
/*     */ 
/* 161 */       department.setDeptSeq(parentDept.getDeptSeq() + addedDept.getId() + ".");
/*     */     }
/*     */ 
/* 165 */     department.setId(addedDept.getId());
/* 166 */     result2 = this.departmentDAO.updateDepartment(department);
/*     */ 
/* 168 */     return (result1) && (result2);
/*     */   }
/*     */ 
/*     */   public boolean updateDepartment(Department department) {
/* 172 */     if (department == null) return false;
/*     */ 
/* 174 */     boolean result1 = false;
/* 175 */     boolean result2 = false;
/*     */ 
/* 177 */     Department oldDept = new Department();
/* 178 */     oldDept = this.departmentDAO.getDepartment(department.getId());
/* 179 */     if (oldDept == null) return false;
/*     */ 
/* 181 */     if (department.getParentId().intValue() == 0) {
/* 182 */       department.setDeptSeq("0." + department.getId() + ".");
/*     */     }
/*     */     else {
/* 185 */       Department parentDept = new Department();
/* 186 */       parentDept = this.departmentDAO.getDepartment(department.getParentId());
/* 187 */       if (parentDept == null) return false;
/*     */ 
/* 189 */       department.setDeptSeq(parentDept.getDeptSeq() + department.getId() + ".");
/*     */     }
/*     */ 
/* 192 */     result1 = this.departmentDAO.updateDepartment(department);
/*     */ 
/* 194 */     if (department.getParentId().compareTo(oldDept.getParentId()) != 0) {
/* 195 */       List subDepts = new ArrayList();
/* 196 */       subDepts = this.departmentDAO.getDepartmentByDeptSeq(oldDept.getDeptSeq());
/* 197 */       if (subDepts != null) {
/* 198 */         for (int i = 0; i < subDepts.size(); i++) {
/* 199 */           Department dept = new Department();
/* 200 */           dept = (Department)subDepts.get(i);
/* 201 */           dept.setDeptSeq(dept.getDeptSeq().replaceFirst(oldDept.getDeptSeq(), department.getDeptSeq()));
/* 202 */           this.departmentDAO.updateDepartment(dept);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 207 */     return result1;
/*     */   }
/*     */ 
/*     */   public String getCurrentDeptUserIdAndSubDeptUserIdsByUserId(Integer userid)
/*     */   {
/* 213 */     return this.departmentDAO.getCurrentDeptUserIdAndSubDeptsUserIdsByUserId(userid);
/*     */   }
/*     */ 
/*     */   public boolean deleteDepartment(Integer id) {
/* 217 */     return this.departmentDAO.deleteDepartment(id);
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.DepartmentServiceImpl
 * JD-Core Version:    0.6.0
 */